package com.gyf.crm.service.impl;

import com.gyf.crm.mapper.CourseOrderMapper;
import com.gyf.crm.mapper.StudentMapper;
import com.gyf.crm.model.CourseOrder;
import com.gyf.crm.model.MonthIncome;
import com.gyf.crm.model.PageResult;
import com.gyf.crm.model.Student;
import com.gyf.crm.service.ICourseOrderService;
import com.gyf.crm.service.IStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CourseOrderServiceImpl implements ICourseOrderService{

    @Autowired
    private CourseOrderMapper courseOrderMapper;

    @Override
    public void save(CourseOrder courseOrder) {

        courseOrderMapper.insert(courseOrder);
    }

    @Override
    public List<CourseOrder> findList(CourseOrder condition, int page, int limit) {
        Map<String,Object> map = new HashMap<String ,Object>();
        map.put("wechat_no",condition.getWechat_no());
        map.put("wechat_mark",condition.getWechat_mark());
        map.put("qq_no",condition.getQq_no());
        map.put("start",(page - 1) * limit);
        map.put("limit",limit);
//        System.out.println("====" + map);
//        return null;
//        courseOrderMapper.findListByMap(map);
        return courseOrderMapper.findList(condition,(page - 1) * limit,limit);
    }

    @Override
    public PageResult<CourseOrder> findPageResult(CourseOrder condition, int page, int limit) {

        PageResult<CourseOrder> pr = new PageResult<CourseOrder>();
        pr.setCount(courseOrderMapper.findCount(condition));
        pr.setData(courseOrderMapper.findList(condition,(page - 1) * limit,limit));
        return pr;
    }

    @Override
    public PageResult<CourseOrder> findPageResult2(CourseOrder condition, int page, int limit) {

        Map<String,Object> map = new HashMap<String ,Object>();
        map.put("condition",condition);
        map.put("start",(page - 1) * limit);
        map.put("limit",limit);
        PageResult<CourseOrder> pr = new PageResult<CourseOrder>();
        pr.setCount(courseOrderMapper.findCountByMap(map));
        pr.setData(courseOrderMapper.findListByMap(map));
        return pr;
    }

    @Override
    public List<MonthIncome> getMonthIncomes() {
        return courseOrderMapper.getMonthIncomes();
    }

    @Override
    public void delete(String order_id) {
        courseOrderMapper.delete(order_id);
    }

    @Override
    public CourseOrder findOrderById(String orderId) {
        return courseOrderMapper.findOrderById(orderId);
    }

    @Override
    public void update(CourseOrder order) {
        courseOrderMapper.update(order);
    }
}
